//============================================================================
// Name        : fgiproute.cc
// Authors     : Luca Fabbrini, Giulio Giovannetti
// Version     : 0.1
// Date        : 16/01/2009
// Copyright   : Copyright (C) 2009 Universita' degli Studi di Firenze
// Licence     : This program is free software; you can redistribute it and/or
//               modify it under the terms of the GNU General Public License
//               as published by the Free Software Foundation; either version 2
//               of the License, or (at your option) any later version.
//
//               This program is distributed in the hope that it will be useful,
//               but WITHOUT ANY WARRANTY; without even the implied warranty of
//               MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//               GNU General Public License for more details.
//
//               You should have received a copy of the GNU General Public License
//               along with this program; if not, write to the Free Software
//               Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// Description : New Route definition for FG MANET routing module.
//============================================================================



#ifndef FGIPROUTE_CC_
#define FGIPROUTE_CC_



#include <stdio.h>
#include <sstream>
#include "IPRoute.h"
#include "InterfaceEntry.h"
#include "fgiproute.h"



std::string FGIPRoute::info() const {
	std::stringstream out;
	out << "srcAddr:"; if (sourceAddress.isUnspecified()) out << "*  "; else out << sourceAddress << "  ";
	out << "dstAddr:"; if (host.isUnspecified()) out << "*  "; else out << host << "  ";
	out << "gw:"; if (gateway.isUnspecified()) out << "*  "; else out << gateway << "  ";
	//out << "mask:"; if (netmask.isUnspecified()) out << "*  "; else out << netmask << "  ";
	out << "metric:" << qualityOfRoute() << " ";
	out << "seqNum:" << seqNum << " ";
	out << "if:"; if (!interfacePtr) out << "*  "; else out << interfacePtr->getName() << "  ";
	out << (type==DIRECT ? "DIRECT" : "REMOTE");
	switch (source) {
		case MANUAL:       out << " MANUAL"; break;
		case IFACENETMASK: out << " IFACENETMASK"; break;
		case RIP:          out << " RIP"; break;
		case OSPF:         out << " OSPF"; break;
		case BGP:          out << " BGP"; break;
		case ZEBRA:        out << " ZEBRA"; break;
		case MANET:        out << " MANET"; break;
		default:           out << " ???"; break;
	}
	return out.str();
}



std::string FGIPRoute::detailedInfo() const {
    return std::string();
}


bool FGIPRoute::operator ==(const FGIPRoute& other){
	if(
		(sourceAddress==other.sourceAddress)&&
		(host==other.host)&&
		(gateway==other.gateway)&&
		(metricT==other.metricT)&&
		(metric==other.metric)
	)
		return true;
	else
		return false;
}



bool FGIPRoute::operator<(FGIPRoute &other) {

	if ((sourceAddress != other.getSourceAddress()) ||(host != other.getHost())){
		opp_error("operator < must be used between route of same commodity");
		return false;
	}

	if (qualityOfRoute() < other.qualityOfRoute())
		return true;
	else
		return false;
}

double FGIPRoute::qualityOfRoute() const{

	return metricT;

}



#endif


